The main data used in this tutorial and in the lecture are about the geolocalisation of french restaurants in Paris. Data is extracted from an official register called SIRENE (Computer system for the business and establishment register) managed by the French National Institute of Statistics and Economic Studies (Insee) and geolocated by Etalab (French task force for Open Data). This register records the civil status of all companies and their establishments (including restaurants). SIRENE has the advantages of being rigorous and exhaustive on the French territory.

Exercise 1 : Manipulate sf objects and associated data.frames

1

Import the iris1 map layer ‘iris_75.shp’ of Paris.
Use sf::st_read().
Reading layer `iris_75' from data source `/home/tim/Documents/prz/satRday/exercises/data/iris_75.shp' using driver `ESRI Shapefile'
Simple feature collection with 992 features and 4 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 643075.6 ymin: 6857477 xmax: 661086.2 ymax: 6867081
epsg (SRID):    NA
proj4string:    +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs

2

Display the basemap of Paris with plot(iris_75). What do you notice ?
We notice that R performs 4 graphs: one graph per variable in the sf object.

3

What is the functionality of the sf::st_geometry() function? What solution do you propose then?
sf::st_geometry() makes it possible to isolate the information contained in the ‘geometry’ column of the sf object. Using it, we put aside other variables (here CODE_IRIS, P14_POP, AREA and CODE_COM).

4

Import the restaurant layer ‘sir.shp’ and display a map of Paris with its restaurants.
Use st_read() and sf::st_geometry().
Reading layer `sir_75' from data source `/home/tim/Documents/prz/satRday/exercises/data/sir_75.shp' using driver `ESRI Shapefile'
Simple feature collection with 23348 features and 7 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 643502.1 ymin: 6857645 xmax: 659766.4 ymax: 6867041
epsg (SRID):    NA
proj4string:    +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs

5

Count the number of restaurant by iris.
Use sf::st_intersects() and sapply().

wwww

Simple feature collection with 6 features and 5 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 650181.1 ymin: 6861761 xmax: 652179 ymax: 6863138
epsg (SRID):    NA
proj4string:    +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs
  CODE_IRIS P14_POP      AREA CODE_COM                       geometry RESTAU
1 751010101     974  64006.07    75101 MULTIPOLYGON (((652096.5 68...     44
2 751010102     167  62671.06    75101 MULTIPOLYGON (((652052.7 68...      6
3 751010103     246  47653.41    75101 MULTIPOLYGON (((651869 6862...     16
4 751010104       3 222656.99    75101 MULTIPOLYGON (((651639.9 68...     10
5 751010105       0 243255.23    75101 MULTIPOLYGON (((650369.8 68...      0
6 751010199       0 234277.01    75101 MULTIPOLYGON (((652096.5 68...      0

6

Using the layer called ‘iris_75’, create a new aggregated map layer called ‘com_75’ which corresponds to the Paris Arrondissements. Also keep in this new layer the information on the population, area and number of restaurant in each municipality.

Information

The map layer called ‘iris_75’ contains the 5 digit codes of arrondissemnt in its variable CODE_COM.
Use the classic functions of dplyr package: select, group_by et summarize. These functions also work with sf objects.

Exercise 2 : Static maps

We would like here to design EPCI maps that combine the number of restaurants and the number of restaurants per 10,000 inhabitants. The EPCI correspond to the level of french intercommunalites.

1

Data preparation:

  • Load ‘fra.shp’ in R: the map layer of the borders of the French metropolitan territory.
  • Load the layer called ‘epci_31.rds’ (which contains the population and the number of restaurants in each EPCI) and create a variable called nb_rest_10000inhab which corresponds to the number of restaurants per 10,000 inhabitants in each territory.
  • Create a vector of quantiles breaks of the nb_rest_10000inhab variable.
  • Create the vector colors which corresponds to a the number of classes defined earlier.
  • Finally, add a variable called typo to ‘epci_31’ which indicates the class of the territory according to the discretization contained in bks for the nb_rest_10000inhab variable (this is needed for ggplot2 maps).

Information

For the creation of ‘bks’ et ‘cols’, use the getBreaks et carto.pal functions of the cartography package. For the creation of the typo variable, you can use the cut function and apply the parameters digit.lab = 2 and include.lowest = TRUE.

2

With the help of cartography package, make the following map which contains in a choropleth layer the variable nb_rest_10000inhab and in a proportional circle layer the variable nb_of_rest. The you can try to do the same map using the ggplot2 and tmaps packages.

With cartography:

With ggplot2:

With tmap:

TODO Timothée

cartography

ggplot2

tmap

TODO Timothée

Exercise 3 : Interactive maps

1

Load the dataset ‘sir_31’ used previously and map the more than 4,000 restaurants of department 31 with the mapview package. Try using different parameters to customize your map.

Information

For example, you can use the map.types, col.regions, label, color, legend, layer.name, homebutton, lwd … parameters of the mapview function.

** TODO To continue Comeetie **



reproducibility

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.7.0
LAPACK: /usr/lib/lapack/liblapack.so.3.7.0

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C               LC_TIME=fr_FR.UTF-8       
 [4] LC_COLLATE=fr_FR.UTF-8     LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8   
 [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mapview_2.6.3     ggplot2_3.1.0     bindrcpp_0.2.2    cartography_2.2.1
[5] dplyr_0.7.8       sf_0.7-2          knitr_1.21        stringr_1.3.1    

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5   xfun_0.4           purrr_0.3.0        lattice_0.20-38   
 [5] colorspace_1.4-0   viridisLite_0.3.0  stats4_3.5.2       htmltools_0.3.6   
 [9] yaml_2.2.0         base64enc_0.1-3    rlang_0.3.1        e1071_1.7-0.1     
[13] pillar_1.3.1       later_0.7.5        glue_1.3.0         withr_2.1.2       
[17] DBI_1.0.0          RColorBrewer_1.1-2 sp_1.3-1           bindr_0.1.1       
[21] plyr_1.8.4         rgeos_0.4-2        munsell_0.5.0      gtable_0.2.0      
[25] unilur_0.4.0.9000  raster_2.8-19      htmlwidgets_1.3    codetools_0.2-15  
[29] evaluate_0.12      httpuv_1.4.5.1     crosstalk_1.0.0    class_7.3-14      
[33] Rcpp_1.0.0         xtable_1.8-3       satellite_1.0.1    scales_1.0.0      
[37] promises_1.0.1     classInt_0.3-1     jsonlite_1.6       webshot_0.5.1     
[41] leaflet_2.0.2      mime_0.6           png_0.1-7          digest_0.6.18     
[45] stringi_1.2.4      shiny_1.2.0        grid_3.5.2         tools_3.5.2       
[49] magrittr_1.5       lazyeval_0.2.1     tibble_2.0.1       crayon_1.3.4      
[53] pkgconfig_2.0.2    assertthat_0.2.0   rmarkdown_1.11     R6_2.3.0          
[57] units_0.6-2        compiler_3.5.2    

  1. In French, IRIS is an acronym of ‘aggregated units for statistical information’. Their target sizes are 2000 residents per basic unit.